<!doctype html>
<html>
  <head>
    <!-- MathJax -->
    <script type="text/javascript"
      src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
    </script>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <title>
      Caffe | Pooling Layer
    </title>

    <link rel="icon" type="image/png" href="/images/caffeine-icon.png">

    <link rel="stylesheet" href="/stylesheets/reset.css">
    <link rel="stylesheet" href="/stylesheets/styles.css">
    <link rel="stylesheet" href="/stylesheets/pygment_trac.css">

    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <!--[if lt IE 9]>
    <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
  </head>
  <body>
  <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-46255508-1', 'daggerfs.com');
    ga('send', 'pageview');
  </script>
    <div class="wrapper">
      <header>
        <h1 class="header"><a href="/">Caffe</a></h1>
        <p class="header">
          Deep learning framework by <a class="header name" href="http://bair.berkeley.edu/">BAIR</a>
        </p>
        <p class="header">
          Created by
          <br>
          <a class="header name" href="http://daggerfs.com/">Yangqing Jia</a>
          <br>
          Lead Developer
          <br>
          <a class="header name" href="http://imaginarynumber.net/">Evan Shelhamer</a>
        <ul>
          <li>
            <a class="buttons github" href="https://github.com/BVLC/caffe">View On GitHub</a>
          </li>
        </ul>
      </header>
      <section>

      <h1 id="pooling">Pooling</h1>

<ul>
  <li>Layer type: <code class="highlighter-rouge">Pooling</code></li>
  <li><a href="http://caffe.berkeleyvision.org/doxygen/classcaffe_1_1PoolingLayer.html">Doxygen Documentation</a></li>
  <li>Header: <a href="https://github.com/BVLC/caffe/blob/master/include/caffe/layers/pooling_layer.hpp"><code class="highlighter-rouge">./include/caffe/layers/pooling_layer.hpp</code></a></li>
  <li>CPU implementation: <a href="https://github.com/BVLC/caffe/blob/master/src/caffe/layers/pooling_layer.cpp"><code class="highlighter-rouge">./src/caffe/layers/pooling_layer.cpp</code></a></li>
  <li>
    <p>CUDA GPU implementation: <a href="https://github.com/BVLC/caffe/blob/master/src/caffe/layers/pooling_layer.cu"><code class="highlighter-rouge">./src/caffe/layers/pooling_layer.cu</code></a></p>
  </li>
  <li>Input
    <ul>
      <li><code class="highlighter-rouge">n * c * h_i * w_i</code></li>
    </ul>
  </li>
  <li>Output
    <ul>
      <li><code class="highlighter-rouge">n * c * h_o * w_o</code>, where h_o and w_o are computed in the same way as convolution.</li>
    </ul>
  </li>
</ul>

<h2 id="parameters">Parameters</h2>

<ul>
  <li>Parameters (<code class="highlighter-rouge">PoolingParameter pooling_param</code>)
    <ul>
      <li>Required
        <ul>
          <li><code class="highlighter-rouge">kernel_size</code> (or <code class="highlighter-rouge">kernel_h</code> and <code class="highlighter-rouge">kernel_w</code>): specifies height and width of each filter</li>
        </ul>
      </li>
      <li>Optional
        <ul>
          <li><code class="highlighter-rouge">pool</code> [default MAX]: the pooling method. Currently MAX, AVE, or STOCHASTIC</li>
          <li><code class="highlighter-rouge">pad</code> (or <code class="highlighter-rouge">pad_h</code> and <code class="highlighter-rouge">pad_w</code>) [default 0]: specifies the number of pixels to (implicitly) add to each side of the input</li>
          <li><code class="highlighter-rouge">stride</code> (or <code class="highlighter-rouge">stride_h</code> and <code class="highlighter-rouge">stride_w</code>) [default 1]: specifies the intervals at which to apply the filters to the input</li>
        </ul>
      </li>
    </ul>
  </li>
  <li>From <a href="https://github.com/BVLC/caffe/blob/master/src/caffe/proto/caffe.proto"><code class="highlighter-rouge">./src/caffe/proto/caffe.proto</code></a>:</li>
</ul>

<figure class="highlight"><pre><code class="language-protobuf" data-lang="protobuf"><span class="kd">message</span> <span class="nc">PoolingParameter</span> <span class="p">{</span>
  <span class="kd">enum</span> <span class="n">PoolMethod</span> <span class="p">{</span>
    <span class="na">MAX</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
    <span class="na">AVE</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
    <span class="na">STOCHASTIC</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span>
  <span class="p">}</span>
  <span class="k">optional</span> <span class="n">PoolMethod</span> <span class="na">pool</span> <span class="o">=</span> <span class="mi">1</span> <span class="p">[</span><span class="k">default</span> <span class="o">=</span> <span class="n">MAX</span><span class="p">];</span> <span class="c1">// The pooling method
</span>  <span class="c1">// Pad, kernel size, and stride are all given as a single value for equal
</span>  <span class="c1">// dimensions in height and width or as Y, X pairs.
</span>  <span class="k">optional</span> <span class="kt">uint32</span> <span class="na">pad</span> <span class="o">=</span> <span class="mi">4</span> <span class="p">[</span><span class="k">default</span> <span class="o">=</span> <span class="mi">0</span><span class="p">];</span> <span class="c1">// The padding size (equal in Y, X)
</span>  <span class="k">optional</span> <span class="kt">uint32</span> <span class="na">pad_h</span> <span class="o">=</span> <span class="mi">9</span> <span class="p">[</span><span class="k">default</span> <span class="o">=</span> <span class="mi">0</span><span class="p">];</span> <span class="c1">// The padding height
</span>  <span class="k">optional</span> <span class="kt">uint32</span> <span class="na">pad_w</span> <span class="o">=</span> <span class="mi">10</span> <span class="p">[</span><span class="k">default</span> <span class="o">=</span> <span class="mi">0</span><span class="p">];</span> <span class="c1">// The padding width
</span>  <span class="k">optional</span> <span class="kt">uint32</span> <span class="na">kernel_size</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span> <span class="c1">// The kernel size (square)
</span>  <span class="k">optional</span> <span class="kt">uint32</span> <span class="na">kernel_h</span> <span class="o">=</span> <span class="mi">5</span><span class="p">;</span> <span class="c1">// The kernel height
</span>  <span class="k">optional</span> <span class="kt">uint32</span> <span class="na">kernel_w</span> <span class="o">=</span> <span class="mi">6</span><span class="p">;</span> <span class="c1">// The kernel width
</span>  <span class="k">optional</span> <span class="kt">uint32</span> <span class="na">stride</span> <span class="o">=</span> <span class="mi">3</span> <span class="p">[</span><span class="k">default</span> <span class="o">=</span> <span class="mi">1</span><span class="p">];</span> <span class="c1">// The stride (equal in Y, X)
</span>  <span class="k">optional</span> <span class="kt">uint32</span> <span class="na">stride_h</span> <span class="o">=</span> <span class="mi">7</span><span class="p">;</span> <span class="c1">// The stride height
</span>  <span class="k">optional</span> <span class="kt">uint32</span> <span class="na">stride_w</span> <span class="o">=</span> <span class="mi">8</span><span class="p">;</span> <span class="c1">// The stride width
</span>  <span class="kd">enum</span> <span class="n">Engine</span> <span class="p">{</span>
    <span class="na">DEFAULT</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
    <span class="na">CAFFE</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
    <span class="na">CUDNN</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span>
  <span class="p">}</span>
  <span class="k">optional</span> <span class="n">Engine</span> <span class="na">engine</span> <span class="o">=</span> <span class="mi">11</span> <span class="p">[</span><span class="k">default</span> <span class="o">=</span> <span class="n">DEFAULT</span><span class="p">];</span>
  <span class="c1">// If global_pooling then it will pool over the size of the bottom by doing
</span>  <span class="c1">// kernel_h = bottom-&gt;height and kernel_w = bottom-&gt;width
</span>  <span class="k">optional</span> <span class="kt">bool</span> <span class="na">global_pooling</span> <span class="o">=</span> <span class="mi">12</span> <span class="p">[</span><span class="k">default</span> <span class="o">=</span> <span class="kc">false</span><span class="p">];</span>
<span class="p">}</span></code></pre></figure>

<h2 id="sample">Sample</h2>
<ul>
  <li>
    <p>Sample (as seen in <a href="https://github.com/BVLC/caffe/blob/master/models/bvlc_reference_caffenet/train_val.prototxt"><code class="highlighter-rouge">./models/bvlc_reference_caffenet/train_val.prototxt</code></a>)</p>

    <div class="highlighter-rouge"><pre class="highlight"><code>layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 3 # pool over a 3x3 region
    stride: 2      # step two pixels (in the bottom blob) between pooling regions
  }
}
</code></pre>
    </div>
  </li>
</ul>


      </section>
  </div>
  </body>
</html>
